﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ScoringClient.Notification
{
    public delegate void NotifyEventHander(NotificationRequest request);

    class NotificationManager
    {
        private List<NotificationRequest> requestRepository;

        public readonly static NotificationManager Instance = new NotificationManager();

        public NotifyEventHander MoveOn { get; set; }

        private NotificationManager()
        {
            requestRepository = new List<NotificationRequest>();
        }

        public NotificationRequest CreateRequest(NotificationAction action)
        {
            return CreateRequest(action, null);
        }

        public NotificationRequest CreateRequest(NotificationAction action, Dictionary<NotiParamType, object> parameters)
        {
            NotificationRequest request = null;
            if (requestRepository.Exists(m => m.Action == action))
            {
                request = requestRepository.Find(m => m.Action == action);
                
                request.Add(parameters);
            }
            else
            {
                request = new NotificationRequest(action, parameters);
                
                requestRepository.Add(request);
            }

            return request;
        }
    }
}
